package com.example.demo.Service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.Entity.Message;
import com.example.demo.GeneralResponse.APIResponse;
import com.example.demo.Repository.IMessageRepository;

/**
 * @version: V0.8
 * @author: 郑皓杰 吴嘉鑫
 * @className: UserService
 * @packageName: com.example.demo.Service
 * @description: 此类是用户共通操作类
 * @data: 2021-07-14
 **/

@Service
public class UserService {
	@Autowired
	private IMessageRepository mesRepository;
	
	/**
	* @author:吴嘉鑫
	* @methodsName: getMyMessage
	* @description: 用户查询自己的讯息
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> getMyMessage(String username){
	
		List<Message> list = mesRepository.findByUserName(username);
		return APIResponse.success("successget",list);
		
	}
	
	/**
	* @author:吴嘉鑫
	* @methodsName: deleteMyMessage
	* @description: 用户删除自己的讯息
	* @param:  Integer empid,Integer rank,String text
	* @return: APIResponse
	* @throws: 
	*/
	public APIResponse<?> deleteMyMessage(Integer mesid){
		Message mes = mesRepository.getById(mesid);
		mesRepository.delete(mes);
		return APIResponse.success("successdelete",null);
		
	}
}
